<?php
	/**
	 * Mootools JS and Ajax Components
	 *
	 */
	class Mootools
	{
		public static $commonJSLoaded = false;
		
		/**
		 * Creates slider map 
		 *
		 * @param array $elements associative array of the map elements/ Each element can have the following attributes: type, columns, title, new_line, html_attributes
		 * @param string $html_attributes html attributes for the table element
		 */
		static function SliderMap(array $elements, $html_attributes)
		{
			//load common JS file
			if (!self::$commonJSLoaded) echo '<script language="JavaScript" type="text/javascript" src="/spherus_framework/core/classes/mootools/mootools.js"></script>';
			self::$commonJSLoaded = true;
			
			echo "<table $html_attributes>";
			echo "<tr><td colspan = '100' style = 'background-color:#999999;'>Header</td></tr>";
			foreach ($elements as $key=>$value)
			{
				if ($value[new_line]) echo "<tr>";
				echo "<td colspan = '{$value[columns]}' $value[html_attributes]>";
				if ($value[type] == 'vertical') self::VerticalSlide($key, $value[title]);
				else self::HorizontalSlide($key, $value[title]);
				echo "</td>";
			}
			echo "</table>";			
		}
		
		/**
		 * Creates vertical slider fot the given element 
		 *
		 * @param string $element_id element id to slide
		 * @param string $title title for the element
		 * @param boolean $use_toggle defines whether to use toggle or not
		 * @param boolean $use_slide_in_out defines whether to use slide in/out or not
		 * @param boolean $use_hide defines whether to use hide or not
		 */
		static function VerticalSlide($element_id, $title = '', $use_toggle = true, $use_slide_in_out = false, $use_hide = false)
		{
			//load common JS file
			if (!self::$commonJSLoaded) echo '<script language="JavaScript" type="text/javascript" src="/spherus_framework/core/classes/mootools/mootools.js"></script>';
			self::$commonJSLoaded = true;
						
			//toolbar with the links
			$toolbar = '';
			
			//script to be executed
			$script = 
			"
			<script  type='text/javascript'>
				window.addEvent('domready', function(){
					
					var mySlide_$element_id = new Fx.Slide('$element_id');
			";
			
			//if slide in/out effect is needed
			if ($use_slide_in_out)
			{
				$script .= "
					$('slidein_$element_id').addEvent('click', function(e){
						e = new Event(e);
						mySlide_$element_id.slideIn();
						e.stop();
					});
					
					$('slideout_$element_id').addEvent('click', function(e){
						e = new Event(e);
						mySlide_$element_id.slideOut();
						e.stop();
					});
				";
					
				$toolbar .= "<a id='slideout_$element_id' href='#'>slideout $title</a>";
				$toolbar .= "<a id='slidein_$element_id' href='#'>slidein $title</a>";
			}

			//if toggle effect is needed
			if ($use_toggle)
			{
				$script .= "
					$('toggle_$element_id').addEvent('click', function(e){
						e = new Event(e);
						mySlide_$element_id.toggle();
						e.stop();
					});
				";
					
				$toolbar .= "<a id='toggle_$element_id' href='#'>toggle $title</a>";
			}

			//if hide effect is needed
			if ($use_hide)
			{
				$script .= "			
					$('hide').addEvent('click', function(e){
						e = new Event(e);
						mySlide.hide();
						e.stop();
					});
				";
				
				$toolbar .= "<a id='hide_$element_id' href='#'>hide $title</a>";
			}
			
			$script .= "	
				}); 
			</script>
			";
			
			echo $script;
			//echo $toolbar;
		}
		
		/**
		 * Creates horizontal slider fot the given element 
		 *
		 * @param string $element_id element id to slide
		 * @param string $title title for the element
		 * @param boolean $use_toggle defines whether to use toggle or not
		 * @param boolean $use_slide_in_out defines whether to use slide in/out or not
		 * @param boolean $use_hide defines whether to use hide or not
		 */
		static function HorizontalSlide($element_id, $title = '', $use_toggle = true, $use_slide_in = false, $use_slide_out = false, $use_hide = false)
		{
			//load common JS file
			if (!self::$commonJSLoaded) echo '<script language="JavaScript" type="text/javascript" src="/spherus_framework/core/classes/mootools/mootools.js"></script>';
			self::$commonJSLoaded = true;
						
			//toolbar with the links
			$toolbar = '';
			
			//script to be executed
			$script = 
			"
			<script  type='text/javascript'>
				window.addEvent('domready', function(){
				
					var mySlide_$element_id = new Fx.Slide('$element_id', {mode: 'horizontal'});
			";
			
			//if slide in/out effect is needed
			if ($use_slide_in)
			{
				$script .= "
					$('slidein_$element_id').addEvent('click', function(e){
						e = new Event(e);
						mySlide_$element_id.slideIn();
						e.stop();
					});
				";
					
				$toolbar .= "<a id='slidein_$element_id' href='#'>slidein $title</a>";
			}
			
			//if slide in/out effect is needed
			if ($use_slide_out)
			{
				$script .= "
					$('slideout_$element_id').addEvent('click', function(e){
						e = new Event(e);
						mySlide_$element_id.slideOut();
						e.stop();
					});
				";
					
				$toolbar .= "<a id='slideout_$element_id' href='#'>slideout $title</a>";
			}
			
			//if toggle effect is needed
			if ($use_toggle)
			{
				$script .= "
					$('toggle_$element_id').addEvent('click', function(e){
						e = new Event(e);
						mySlide_$element_id.toggle();
						e.stop();
					});
				";
					
				$toolbar .= "<a id='toggle_$element_id' href='#'>toggle $title</a>";
			}

			//if hide effect is needed
			if ($use_hide)
			{
				$script .= "			
					$('hide_$element_id').addEvent('click', function(e){
						e = new Event(e);
						mySlide_$element_id.hide();
						e.stop();
					});
				"; 
				
				$toolbar .= "<a id='hide_$element_id' href='#'>hide $title</a>";
			}
					
			$script .= "	
				}); 
			</script>
			";
							
			echo $script;
			//echo $toolbar;
		}
	
		/**
		 * Creates an accordion pane
		 *
		 * @param string $id accordion pane id
		 * @param array $elements accordion pane elements. Each element is an array swith 'title' and 'content' fields
		 * @param string $titleStyle css styles for the pane titles
		 * @param unknown_type $contentStyle css styles for the pane contents
		 */
		static function AccordionPane($id, array $elements, $titleStyle = "color: #222222; padding: 2px 5px;padding: 2px 5px; background: #eeeeee;border-bottom: 1px solid #ddd; border-right: 1px solid #ddd; border-top: 1px solid #f5f5f5; border-left: 1px solid #f5f5f5; font-size: 11px; font-family: 'Andale Mono', sans-serif;", $contentStyle = '')
		{
			//load common JS file
			if (!self::$commonJSLoaded) echo '<script language="JavaScript" type="text/javascript" src="/spherus_framework/core/classes/mootools/mootools.js"></script>';
			self::$commonJSLoaded = true;
			
			//generate html for the pane
			echo "<div id='accordion_$id'>";
			foreach ($elements as $element)
			{
				echo "<h3 onMouseOver = 'this.style.cursor = \"pointer\"' class='toggler atStart' style = 'margin: 0px; $titleStyle'>$element[title]</h3>";
				echo "<div class='element atStart' style = '$contentStyle'>$element[content]</div>";
			}
			echo "</div>";
			
			//generate JavaScript for the pane
			echo "
				<script>
				var accordion_$id = new Accordion('h3.atStart', 'div.atStart', {
					opacity: false,
					onActive: function(toggler, element){
						toggler.setStyle('color', '#ff3300');
					},
				 
					onBackground: function(toggler, element){
						toggler.setStyle('color', '#222');
					}
				}, $('accordion_$id'));
				</script>			
			";
		}
	}
?>